package com.szl.group.config.auth.custom;

import com.szl.group.entity.SysUserDO;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * description:
 * author: shenxiaolong
 * date: 2020/6/21  16:48
 */
public class CustomUserDetails implements UserDetails {

    private static final long serialVersionUID = 1L;

    private String username;
    private String password;
    private boolean enabled;  //账号是否可用

    private Collection<? extends GrantedAuthority> authorities;

    //无参构造
    public CustomUserDetails() {
    }

    //用User构造
    public CustomUserDetails(SysUserDO user) {
        this.username = user.getUsername();
        this.password = user.getPassword();
        this.enabled = user.getEnabled() == 1;
    }


    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;

    }

    public void setAuthorities(Collection<? extends GrantedAuthority> authorities) {
        this.authorities = authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return enabled;
    }
}
